/*
 * @Descripttion: GGB
 * @version: 1.0
 * @Author: GGB
 * @Date: 2021-08-17 14:34:54
 * @LastEditors: GGB
 * @LastEditTime: 2021-08-17 14:48:43
 */
import 'package:flutter/material.dart';
import 'package:flutter_data_center/utills/color_utils.dart';

class DatePicker extends StatelessWidget {
  const DatePicker({Key key, this.selectedDate, this.onChange})
      : super(key: key);
  final DateTime selectedDate;
  final ValueChanged<DateTime> onChange;

  @override
  Widget build(BuildContext context) {
    String date =
        selectedDate != null ? selectedDate.toString().split(" ")[0] : '今日';
    return Row(
      mainAxisAlignment: MainAxisAlignment.center,
      crossAxisAlignment: CrossAxisAlignment.center,
      children: [
        Text(
          date,
          style: TextStyle(
            fontSize: 16,
            color: gColor("#545454"),
          ),
        ),
        IconButton(
          icon: Icon(Icons.arrow_drop_down),
          onPressed: () async {
            var result = await showDatePicker(
              context: context,
              initialDate: selectedDate ?? DateTime.now(),
              firstDate: DateTime(2020),
              lastDate: DateTime.now(),
            );
            if (result != null) {
              onChange(result);
            }
          },
        ),
      ],
    );
  }
}
